#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define vec vector<int>
#define y1 y_____hahahaha_____1

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;

int read(){int x = 0,sgn = 1;char ch = getchar();for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;for(;isdigit(ch);ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48); return x * sgn;}

const int N = 2.5e5+10;
const int mod = 998244353;

int n,m;

struct mat{
	int arr[5][5];
	mat(vector<vector<int> >x){for(int i = 0;i < 4;i++) for(int j = 0;j < 4;j++) arr[i][j] = x[i][j];}
	int * operator [](int x){return arr[x];}
	const int * operator [](int x)const{return arr[x];}
	mat(){memset(arr,0,sizeof arr);}
	friend mat operator * (mat a,mat b){
		mat c;
		for(int i = 0;i < 4;i++)
			for(int j = 0;j < 4;j++)
				if(a[i][j])
					for(int k = 0;k < 4;k++)
						c[i][k] = (c[i][k] + (ll) a[i][j] * b[j][k] % mod) % mod;
		return c;
	}
	friend mat operator + (mat a,mat b){mat c; for(int i = 0;i < 4;i++) for(int j = 0;j < 4;j++) c[i][j] = (a[i][j] + b[i][j]) % mod;return c;}
	friend bool operator != (mat a,mat b){for(int i = 0;i < 4;i++) for(int j = 0;j < 4;j++) if(a[i][j] != b[i][j]) return 1; return 0;}
}val[N<<2],lz[N<<2],a[N];

const mat I = mat({{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}});

void mul(int o,mat v){val[o] = val[o] * v; lz[o] = lz[o] * v;}

void build(int o = 1,int l = 1,int r = n){lz[o] = I; if(l == r) return val[o] = a[l],void(); int mid = l + r >> 1; build(o << 1,l,mid); build(o << 1 | 1,mid + 1,r);val[o] = val[o << 1] + val[o << 1 | 1];}

void pushdown(int o){if(lz[o] != I) mul(o<<1,lz[o]),mul(o<<1|1,lz[o]),lz[o] = I;}

void upd(int xl,int xr,mat v,int o = 1,int l = 1,int r = n){
	if(xl == l && xr == r) return mul(o,v); int mid = l + r >> 1; pushdown(o); if(xr <= mid) upd(xl,xr,v,o<<1,l,mid); else if(xl > mid) upd(xl,xr,v,o<<1|1,mid+1,r); else upd(xl,mid,v,o<<1,l,mid),upd(mid + 1,xr,v,o<<1|1,mid + 1,r); val[o] = val[o << 1] + val[o << 1 | 1];
}

mat query(int xl,int xr,int o = 1,int l = 1,int r = n){
	if(xl == l && xr == r) return val[o]; int mid = l + r >> 1; pushdown(o); if(xr <= mid) return query(xl,xr,o<<1,l,mid); else if(xl > mid) return query(xl,xr,o<<1|1,mid+1,r); else return query(xl,mid,o<<1,l,mid) + query(mid + 1,xr,o<<1|1,mid+1,r);
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in; for(int i = 1;i <= n;i++) a[i][0][0] = in,a[i][0][1] = in,a[i][0][2] = in,a[i][0][3] = 1; build();
	m = in;
	while(m--){
		int op = in,l = in,r = in; mat v = I; if(op == 7) {v = query(l,r);printf("%d %d %d\n",v[0][0],v[0][1],v[0][2]);continue;}
		if(op == 1) v[1][0] = 1; else if(op == 2) v[2][1] = 1;else if(op == 3) v[0][2] = 1;
		else if(op == 4) v[3][0] = in; else if(op == 5) v[1][1] = in;else v[2][2] = 0,v[3][2] = in;
		upd(l,r,v);
	}
	return 0;
}
